package com.qh.yyxt.pojo;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.qh.yyxt.pojo.entity.thing.Thing;
import com.qh.yyxt.pojo.entity.thing.ThingSize;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class ThingDTO
{
    @JsonProperty("id")
    private Integer id;
    @JsonProperty("name")
    private String name;
    @JsonProperty("num")
    private Integer num;
    @JsonProperty("unit")
    private String unit;
    @JsonProperty("image")
    private String image;
    private List<ThingSize> list=new ArrayList();
    public void setDTO(Thing thing,List<ThingSize>list)
    {
        if(thing!=null) {
            this.id = thing.getId();
            this.name = thing.getName();
            this.num = thing.getNum();
            this.unit = thing.getUnit();
            this.image=thing.getImage();
            //试试有没有问题【byte->image】
//            ByteArrayInputStream in = new ByteArrayInputStream(thing.getImage());
//            try {
//                this.image = ImageIO.read(in);
//                in.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }

        }
        if(list!=null)
        {
            this.list=list;
        }
    }
}
